#ifndef GAMESCENE_H
#define GAMESCENE_H

#include <QGraphicsScene>
#include <QTimer>
#include <QMap>
#include <QKeyEvent>
#include <QGraphicsSceneMouseEvent>
#include <QLabel>

class Player;
class House;
class QLabel;

class GameScene : public QGraphicsScene
{
    Q_OBJECT

public:
    explicit GameScene(QObject *parent = nullptr);
    ~GameScene();

    // 将 initScene 声明为公有函数
    void initScene();

protected:
    void keyPressEvent(QKeyEvent *event) override;
    void keyReleaseEvent(QKeyEvent *event) override;
    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;

private slots:
    void gameLoop();
    void spawnZombie();

private:
    // 将 initScene 从私有区域移除
    void checkCollisions();
    void updateUI();
    void gameOver();

    Player *m_player;
    House *m_house;

    QTimer m_gameTimer;
    QTimer m_zombieSpawnTimer;

    QMap<int, bool> m_keysPressed;
    QPointF m_mousePos;

    QGraphicsTextItem* m_scoreText;
    QGraphicsTextItem* m_sunshineText;
    QGraphicsTextItem* m_houseHealthText;

    int m_score;
    int m_sunshine;
};

#endif // GAMESCENE_H
